
package com.ami.vmedia;

import java.awt.Point;
import java.util.Timer;

import com.ami.iusb.CDROMRedir;
import com.ami.iusb.FloppyRedir;
import com.ami.iusb.HarddiskRedir;
import com.ami.iusb.IUSBRedirSession;
import com.ami.iusb.RedirectionException;
import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.JViewer;
import com.ami.kvm.jviewer.gui.InfoDialog;
import com.ami.kvm.jviewer.gui.JViewerApp;
import com.ami.kvm.jviewer.gui.LocaleStrings;
import com.ami.kvm.jviewer.gui.SinglePortKVM;
import com.ami.vmedia.gui.UpdateBytesRead;
import com.ami.vmedia.gui.VMDialog;
import com.ami.vmedia.gui.VMFrame;
import com.ami.vmedia.gui.VMPane;
import com.ami.vmedia.gui.VMStatusBar;

public class VMApp {
	public static final int DEVICE_TYPE_CDROM = 0;
	public static final int DEVICE_TYPE_FLOPPY = 1;
	public static final int DEVICE_TYPE_HD_USB = 2;
	public static final int DEFAULT_NUM_DRIVES = 1;
	public static final int IMAGE_TYPE_CDROM = 1;
	public static final int IMAGE_TYPE_FLOPPY = 2;
	public static final int IMAGE_TYPE_HARDDISK = 3;
	public static final int MAX_IMAGE_PATH_COUNT = 5;
	private static int height = 0;
	private static int width = 0;
	private static Point windowPos = new Point(0, 0);

	public static final int CD_MEDIA = 0;

	public static final int FD_MEDIA = 1;

	public static final int HD_MEDIA = 2;
	public static final int STATUS_TAB = 3;
	public static String[][] cdImagePath;
	public static String[][] fdImagePath;
	public static String[][] hdImagePath;
	private static VMApp vmApp = new VMApp();
	private static VMPane vmPane = null;
	private static VMStatusBar statusPanel = null;
	private static VMFrame vmFrame = null;
	private static VMDialog vmDialog = null;
	private int numCD;
	private int numFD;
	private int numHD;
	private int freeCDNum = 0;
	private int freeFDNum = 0;
	private int freeHDNum = 0;
	private String[] cdDriveList;
	private String[] fdDriveList;
	private String[] hdDriveList;
	private static String lang = null;
	private static String ip;
	private IUSBRedirSession iusbRedirSession = null;
	private static DeviceDetector devDetector = null;
	private static RedirectionStatusMonitor redirectionStatusMonitor = null;

	private static String webSessionToken;
	private static String kvmToken;
	private RedirectionController redirectionController = null;
	private static Timer updateBytesTimer = null;

	public static void launchApp() {
		statusPanel = new VMStatusBar();

		if (JViewer.isVMApp()) {
			vmFrame = new VMFrame();
		} else {
			vmDialog = new VMDialog();
			setVMDialog(vmDialog);
			JViewerApp.getInstance().setVMDialog(vmDialog);
		}
		updateBytesTimer = new Timer();
		updateBytesTimer.schedule(new UpdateBytesRead(), 0L, 1000L);

		if ((JViewer.isVMApp()) && (JViewer.isSinglePortEnabled())) {

			JViewerApp.getInstance().getConnection().setKvmSSLVerify(false);
			JViewerApp.getInstance().setSinglePortKvm(
					new SinglePortKVM(JViewer.getIp(), JViewer.getKvmPort(), JViewer.getWebPort(), JViewer.isUseSSL()));
		}
	}

	public VMApp() {
		webSessionToken = JViewer.getWebSessionToken();
		kvmToken = JViewer.getKVMToken();
		this.redirectionController = new RedirectionController();
	}

	public static VMApp getInstance() {
		return vmApp;
	}

	public static VMPane getVMPane() {
		return vmPane;
	}

	public static void setVMPane(VMPane paramVMPane) {
		vmPane = paramVMPane;
	}

	public static VMStatusBar getVMStatusPanel() {
		return statusPanel;
	}

	public static VMFrame getVMFrame() {
		return vmFrame;
	}

	public static VMDialog getVMDialog() {
		return vmDialog;
	}

	public static void setVMDialog(VMDialog paramVMDialog) {
		vmDialog = paramVMDialog;
	}

	public int getNumCD() {
		return this.numCD;
	}

	public void setNumCD(int paramInt) {
		String[][] arrayOfString = (String[][]) null;
		int i = this.numCD;
		arrayOfString = cdImagePath;
		this.numCD = paramInt;
		cdImagePath = new String[paramInt][5];
		if (i > paramInt)
			i = paramInt;
		if (arrayOfString != null) {
			for (int j = 0; j < i; j++) {
				cdImagePath[j] = arrayOfString[j];
			}
		}
	}

	public int getNumFD() {
		return this.numFD;
	}

	public void setNumFD(int paramInt) {
		String[][] arrayOfString = (String[][]) null;
		int i = this.numFD;
		arrayOfString = fdImagePath;
		this.numFD = paramInt;
		fdImagePath = new String[paramInt][5];
		if (i > paramInt)
			i = paramInt;
		if (arrayOfString != null) {
			for (int j = 0; j < i; j++) {
				fdImagePath[j] = arrayOfString[j];
			}
		}
	}

	public int getNumHD() {
		return this.numHD;
	}

	public void setNumHD(int paramInt) {
		String[][] arrayOfString = (String[][]) null;
		int i = this.numHD;
		arrayOfString = hdImagePath;
		this.numHD = paramInt;
		hdImagePath = new String[paramInt][5];
		if (i > paramInt)
			i = paramInt;
		if (arrayOfString != null) {
			for (int j = 0; j < i; j++)
				hdImagePath[j] = arrayOfString[j];
		}
	}

	public int getFreeCDNum() {
		return this.freeCDNum;
	}

	public void setFreeCDNum(int paramInt) {
		this.freeCDNum = paramInt;
	}

	public int getFreeFDNum() {
		return this.freeFDNum;
	}

	public void setFreeFDNum(int paramInt) {
		this.freeFDNum = paramInt;
	}

	public int getFreeHDNum() {
		return this.freeHDNum;
	}

	public void setFreeHDNum(int paramInt) {
		this.freeHDNum = paramInt;
	}

	public void updateFreeDeviceStatus() {
		if ((vmFrame != null) && (vmFrame.isShowing())) {
		}
	}

	public String getRomanNumber(int paramInt) {
		String str = null;
		int i = 8544;
		if (paramInt < 12) {
			if (paramInt > 0)
				i += paramInt;
			char c = (char) i;
			str = String.valueOf(c);
		} else {
			str = String.valueOf(paramInt);
		}
		return str;
	}

	public static String getLanguage() {
		return lang;
	}

	public static void setLanguage(String paramString) {
		lang = paramString;
		LocaleStrings.setLanguageID(lang);
	}

	public static void setDefaultLanguage() {
		lang = "EN";
	}

	public static String getIp() {
		return ip;
	}

	public void createIUSBRedirectionSession() {
		this.iusbRedirSession = new IUSBRedirSession();
	}

	public IUSBRedirSession getIUSBRedirSession() {
		return this.iusbRedirSession;
	}

	public String[] getCDROMList() {
		String[] arrayOfString = null;
		try {
			CDROMRedir localCDROMRedir = new CDROMRedir(true);
			arrayOfString = localCDROMRedir.getCDROMList();
			System.gc();
		} catch (RedirectionException localRedirectionException) {
			Debug.out.println("Exception occured while getCDROMList()");
			Debug.out.println(localRedirectionException);
		} catch (Error localError) {
			Debug.out.println("Exception occured while getCDROMList()");
			Debug.out.println(localError);
		} catch (Exception localException) {
			Debug.out.println("Exception occured while getCDROMList()");
			Debug.out.println(localException);
		}
		return arrayOfString;
	}

	public String[] getFloppyList() {
		String[] arrayOfString = null;
		try {
			if (JViewer.IsClientAdmin()) {
				FloppyRedir localFloppyRedir = new FloppyRedir(true);
				arrayOfString = localFloppyRedir.getFloppyList();
				System.gc();
			}
		} catch (Error localError) {
			Debug.out.println("Exception occured while getFloppyList()");
			Debug.out.println(localError);
		} catch (Exception localException) {
			Debug.out.println("Exception occured while getFloppyList()");
			Debug.out.println(localException);
		}
		return arrayOfString;
	}

	public String[] getHDDUSBList() {
		String[] arrayOfString = null;
		try {
			if (JViewer.IsClientAdmin()) {
				HarddiskRedir localHarddiskRedir = new HarddiskRedir(true);
				arrayOfString = localHarddiskRedir.getUSBHDDList();
				System.gc();
			}
		} catch (Error localError) {
			Debug.out.println("Exception occured while getHDDUSBList()");
			Debug.out.println(localError);
		} catch (Exception localException) {
			Debug.out.println("Exception occured while getHDDUSBList()");
			Debug.out.println(localException);
		}
		return arrayOfString;
	}

	public String[] getHarddiskFixedList() {
		String[] arrayOfString = null;
		if (true == JViewer.IsClientAdmin()) {
			try {
				if ((JViewer.getOEMFeatureStatus() & 0x2) != 2L) {
					HarddiskRedir localHarddiskRedir = new HarddiskRedir(true);
					arrayOfString = localHarddiskRedir.getHarddiskFixedList();
					System.gc();
				}
			} catch (Error localError) {
				Debug.out.println("Exception occured while getHarddiskFixedList()");
				Debug.out.println(localError);
			} catch (Exception localException) {
				Debug.out.println("Exception occured while getHarddiskFixedList()");
				Debug.out.println(localException);
			}
		}
		return arrayOfString;
	}

	public String[] getEntireHarddiskList() {
		String[] arrayOfString = null;
		try {
			HarddiskRedir localHarddiskRedir = new HarddiskRedir(true);
			arrayOfString = localHarddiskRedir.getEntireHarddiskList();
			System.gc();
		} catch (Error localError) {
			Debug.out.println("Exception occured while getEntireHarddiskList()");
			Debug.out.println(localError);
		} catch (Exception localException) {
			Debug.out.println("Exception occured while getEntireHarddiskList()");
			Debug.out.println(localException);
		}
		return arrayOfString;
	}

	public String[] getDeviceDriveList(int paramInt) {
		String[] arrayOfString1 = null;
		if (paramInt == 0) {
			this.cdDriveList = getCDROMList();
			arrayOfString1 = this.cdDriveList;
		} else if (paramInt == 1) {
			this.fdDriveList = getFloppyList();
			arrayOfString1 = this.fdDriveList;
		} else if (paramInt == 2) {
			String[] arrayOfString2 = getHDDUSBList();
			String[] arrayOfString3 = null;

			if ((true == JViewer.IsClientAdmin()) && ((JViewer.getOEMFeatureStatus() & 0x2) != 2L)) {
				arrayOfString3 = getHarddiskFixedList();
			}
			int i = 0;

			if ((arrayOfString2 != null) || (arrayOfString3 != null)) {
				int j = 0;

				if (arrayOfString2 != null)
					j += arrayOfString2.length;
				if (arrayOfString3 != null) {
					j += arrayOfString3.length;
				}
				this.hdDriveList = new String[j];
				int k;
				if (arrayOfString3 != null) {
					for (k = 0; k < arrayOfString3.length; i++) {
						this.hdDriveList[i] = arrayOfString3[k];
						this.hdDriveList[i] = this.hdDriveList[i].concat(LocaleStrings.getString("G_16_VMD"));
						k++;
					}
				}

				if (arrayOfString2 != null) {
					for (k = 0; k < arrayOfString2.length; k++) {
						this.hdDriveList[i] = arrayOfString2[k];
						this.hdDriveList[i] = this.hdDriveList[i].concat(" - USB");
						i++;
					}
				}
			} else {
				this.hdDriveList = null;
			}
			arrayOfString1 = this.hdDriveList;
		}
		return arrayOfString1;
	}

	public String[] getCDDriveList() {
		return this.cdDriveList;
	}

	public void setCDDriveList(String[] paramArrayOfString) {
		this.cdDriveList = paramArrayOfString;
	}

	public String[] getFDDriveList() {
		return this.fdDriveList;
	}

	public void setFDDriveList(String[] paramArrayOfString) {
		this.fdDriveList = paramArrayOfString;
	}

	public String[] getHDDriveList() {
		return this.hdDriveList;
	}

	public void setHDDriveList(String[] paramArrayOfString) {
		this.hdDriveList = paramArrayOfString;
	}

	public static String getWebSessionToken() {
		return webSessionToken;
	}

	public static void setWebSessionToken(String paramString) {
		webSessionToken = paramString;
	}

	public static String getKVMToken() {
		return kvmToken;
	}

	public RedirectionController getRedirectionController() {
		return this.redirectionController;
	}

	public static void setKVMToken(String paramString) {
		kvmToken = paramString;
	}

	public static Timer getUpdateBytesTimer() {
		return updateBytesTimer;
	}

	public boolean isCDRedirRunning(int paramInt) {
		boolean bool = false;
		if (this.iusbRedirSession.getCDROMRedirStatus(paramInt) == 1) {
			bool = true;
		}
		return bool;
	}

	public boolean isFDRedirRunning(int paramInt) {
		boolean bool = false;
		if (this.iusbRedirSession.getFloppyRedirStatus(paramInt) == 1) {
			bool = true;
		}
		return bool;
	}

	public boolean isHDRedirRunning(int paramInt) {
		boolean bool = false;
		if (this.iusbRedirSession.getHarddiskRedirStatus(paramInt) == 1) {
			bool = true;
		}
		return bool;
	}

	public boolean isCDRedirRunning() {
		boolean bool = false;
		try {
			for (int i = 0; i < this.numCD; i++) {
				if (this.iusbRedirSession.getCDROMRedirStatus(i) == 1) {
					bool = true;
				}
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
			bool = false;
		}
		return bool;
	}

	public boolean isFDRedireRunning() {
		boolean bool = false;
		try {
			for (int i = 0; i < this.numFD; i++) {
				if (this.iusbRedirSession.getFloppyRedirStatus(i) == 1) {
					bool = true;
				}
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
			bool = false;
		}
		return bool;
	}

	public boolean isHDRedireRunning() {
		boolean bool = false;
		try {
			for (int i = 0; i < this.numHD; i++) {
				if (this.iusbRedirSession.getHarddiskRedirStatus(i) == 1) {
					bool = true;
				}
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
			bool = false;
		}
		return bool;
	}

	public void generalErrorMessage(String paramString1, String paramString2) {
		InfoDialog.showDialog(vmFrame, paramString2, paramString1, 2);
	}

	public void initDeviceDetector() {
		if (devDetector == null) {
			devDetector = new DeviceDetector();
			devDetector.setName("DeviceDetector");
		}
	}

	public void initRedirectionStatusMonitor() {
		if (redirectionStatusMonitor == null) {
			redirectionStatusMonitor = new RedirectionStatusMonitor();
			redirectionStatusMonitor.setName("RedirectionStatusMonitor");
		}
	}

	public static void stopDeviceDetector() {
		if (devDetector != null)
			devDetector.stopDeviceDetector();
		devDetector = null;
	}

	public static void stopRedirectionStatusMonitor() {
		if (redirectionStatusMonitor != null)
			redirectionStatusMonitor.stopRedirectionStatusMonitior();
		redirectionStatusMonitor = null;
	}

	public static void exit(int paramInt) {
		stopDeviceDetector();
		stopRedirectionStatusMonitor();
//		System.exit(paramInt);
	}

	public static int getWidth() {
		return width;
	}

	public static int getHeight() {
		return height;
	}

	public static void setWidth(int paramInt) {
		width = paramInt;
	}

	public static void setHeight(int paramInt) {
		height = paramInt;
	}

	public static Point getWindowPos() {
		return windowPos;
	}

	public static void setWindowPos(Point paramPoint) {
		windowPos = paramPoint;
	}
}

/*
 * Location: D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\vmedia\VMApp.class
 * Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */